package cn.iocoder.yudao.module.eval.dal.mysql.question;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.eval.controller.admin.question.vo.EvalQuestionCategoryPageReqVO;
import cn.iocoder.yudao.module.eval.dal.dataobject.question.EvalQuestionCategoryDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 题库分类 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface EvalQuestionCategoryMapper extends BaseMapperX<EvalQuestionCategoryDO> {

    default PageResult<EvalQuestionCategoryDO> selectPage(EvalQuestionCategoryPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<EvalQuestionCategoryDO>()
                .likeIfPresent(EvalQuestionCategoryDO::getCategoryCode, reqVO.getCategoryCode())
                .likeIfPresent(EvalQuestionCategoryDO::getCategoryName, reqVO.getCategoryName())
                .eqIfPresent(EvalQuestionCategoryDO::getParentId, reqVO.getParentId())
                .eqIfPresent(EvalQuestionCategoryDO::getCategoryLevel, reqVO.getCategoryLevel())
                .eqIfPresent(EvalQuestionCategoryDO::getCategoryStatus, reqVO.getCategoryStatus())
                .betweenIfPresent(EvalQuestionCategoryDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(EvalQuestionCategoryDO::getCategorySort)
                .orderByDesc(EvalQuestionCategoryDO::getId));
    }

    default EvalQuestionCategoryDO selectByCategoryCode(String categoryCode) {
        return selectOne(EvalQuestionCategoryDO::getCategoryCode, categoryCode);
    }

    default List<EvalQuestionCategoryDO> selectListByParentId(Long parentId) {
        return selectList(new LambdaQueryWrapperX<EvalQuestionCategoryDO>()
                .eq(EvalQuestionCategoryDO::getParentId, parentId)
                .orderByAsc(EvalQuestionCategoryDO::getCategorySort));
    }

    default List<EvalQuestionCategoryDO> selectListByCategoryLevel(Integer categoryLevel) {
        return selectList(new LambdaQueryWrapperX<EvalQuestionCategoryDO>()
                .eq(EvalQuestionCategoryDO::getCategoryLevel, categoryLevel)
                .orderByAsc(EvalQuestionCategoryDO::getCategorySort));
    }

    default List<EvalQuestionCategoryDO> selectListByCategoryStatus(Integer categoryStatus) {
        return selectList(new LambdaQueryWrapperX<EvalQuestionCategoryDO>()
                .eq(EvalQuestionCategoryDO::getCategoryStatus, categoryStatus)
                .orderByAsc(EvalQuestionCategoryDO::getCategorySort));
    }

}
